import { TargetState } from "framework/FSM/DecisionTree/DecisionTargetState";
 
 
import { DecisionTreeTransition } from "framework/FSM/Transition/DecisionTreeTransition";
 
import { HierarchicalStateMachine } from "framework/FSM/HierarchicalStateMachine";
import { BehaviorMode } from "../../Control/State/creep/behaviorMode/BehaviorMode";
import { TaskMode } from "../../Control/State/creep/TaskMode/TaskMode";
import { DecisionIsCreepTaskMode } from "../../Control/Decision/creep/DecisionIsCreepTaskMode";
import { CreepBoostState } from "../../Control/State/creep/prepare/CreepBoostState";
import { DecisionIsCreepBoost } from "../../Control/Decision/creep/DecisionIsCreepBoost";
import { UpdateResult } from "framework/FSM/HSMBase";
import { cpu_used } from "utils/decorate/decorate";

export class CreepStateMachine extends HierarchicalStateMachine
{
     
    public Update(arg: IStateArg<Creep, ITask<ITaskData, keyof ITaskDeclare>>): UpdateResult {
        const cpu1 = Game.cpu.getUsed();
        const ert=  super.Update(arg)
        const cpu2 = Game.cpu.getUsed();
        arg.entity.log("info","cpu",`[${cpu2 - cpu1}]`,`任务:`,arg.entity.memory.taskid,'任务类型');
        return ert;
    }
}
export class AICreepFactory
{
    static CreateCreep()
    {
        
        const autoMode = this.CreepAutoMode();
        const taskMode = this.CreepTaskMode();
        const boostState = this.CreateBoost();
        const HSM_Creep = new HierarchicalStateMachine([boostState,autoMode,taskMode,]);
        const decision_boost = new DecisionIsCreepBoost(
            undefined,
            new DecisionIsCreepTaskMode(
                new TargetState(taskMode),
                new TargetState(autoMode)
                )
            );
        const decision_auto  = new DecisionIsCreepBoost(
            new TargetState(boostState), 
            new DecisionIsCreepTaskMode(
                new TargetState(taskMode)
                )
                );
        const decision_task   = new DecisionIsCreepBoost(
            new TargetState(boostState), 
            new DecisionIsCreepTaskMode(
                undefined,
                new TargetState(autoMode)
                )
                );
        autoMode.addTransition(new DecisionTreeTransition(decision_auto));
        taskMode.addTransition(new DecisionTreeTransition(decision_task));
        boostState.addTransition(new DecisionTreeTransition(decision_boost))
        return HSM_Creep;
    }

    // 角色自主行为控制器
    static CreepAutoMode()
    {
         
        return  new BehaviorMode()
    }
    
    // 爬虫角色任务模式
    static CreepTaskMode()
    {
        
        return new TaskMode()
    }

     static CreateBoost()
     {
        return new CreepBoostState()
     }
}